<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib  prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
	<title>阅学网欢迎您！</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta name="Keywords" content="">
	<meta name="description" content="">
	<jsp:include page="/user/common.jsp" />
  </head>
<body>
<%--账号管理页面 --%>
	<jsp:include page="/user/question/questionLeft.jsp"></jsp:include>
	<div style="float: left;width:980px;margin-top: 8px;margin-left: 30px;">
		<table class="table">
			<button type="button" class="btn btn-primary btn-sm" onclick="javascript:showDiv();">添加</button>
			  <thead>
			    <tr>
			      <th><input type="checkbox"></th>
			      			<th>标题</th>
							<th>时间</th>
							<th>浏览</th>
							<th>收藏</th>
							<th>关注</th>
							<th>状态</th>
							<th>缓急程度</th>
							<th>操作</th>
			      </tr>
			  </thead>
 			 <tbody>
  					<c:forEach items="${questions }" var="question">
						<tr>
							<td><input type="checkbox"></td>
							<td>${question.questionTitle }</td>
							<td><fmt:formatDate value="${question.createDate}" type="both" pattern="yyyy-MM-dd HH:mm:ss" /></td>
							<td>${question.questionClick }</td>
							<td>${question.questionCollection }</td>
							<td>${question.questionAbout }</td>
							<td>${question.isFin ==1?"已关闭":"未关闭" }</td>
							<td>${question.questionLevel ==0?"普通":"急求回答" }</td>
							<td>
								<a  class="btn btn-warning btn-sm" href="user/question/deleteQuestion?questionId=${question.id }">删除</a>
								<a  class="btn btn-info btn-sm" href="user/question/toEditQuestion?questionId=${question.id }">编辑</a>
								<c:if test="${question.isFin ==1}">
									<a  class="btn btn-info btn-sm" href="javascript:void($.util.alert('该问题已关闭，请勿再次关闭!'));">关闭</a>
								</c:if>
								<c:if test="${question.isFin ==0}">
									<a  class="btn btn-info btn-sm" href="user/question/closeQuestion?questionId=${question.id }">关闭</a>
								</c:if>
								<a  class="btn btn-info btn-sm" href="user/question/showAnswers?questionId=${question.id }">查看回答</a>
							</td>
						</tr>
				</c:forEach>
  			</tbody>
		</table>
	</div>
	<div id="question-add-div" class="question-add-div" style="display:none;">
		<div class="question-add-title">
			<span style="margin-top: -6px;float: left;">添加提问</span>
		</div>
		<div>
				<form action="user/question/saveQuestion" method="post" id="question-add-form">
		 		<table>
		 				<tr>
		 						<td class="question-add-td">标题:</td>
		 						<td><input type="text" value="" name="questionTitle" id="questionTitle" class="form-control" /></td>
		 				</tr>	
		 					<tr>
		 							<td>问题类型:</td>
		 							<td>
		 									<select name="questionTypeId" class="form-control" id="questionTypeId">
		 											<c:forEach items="${questionTypes }" var="questionType" >
				 											<option value="${questionType.id }">${questionType.questionTypeName }</option>
		 											</c:forEach>
		 									</select>
		 							</td>
		 					</tr>	
		 					<tr>
		 							<td>问题等级:</td>
		 							<td>
		 									<select name="questionLevel" class="form-control">
		 											<option value="0">普通</option>
		 											<option value="1">急求回答</option>
		 									</select>
		 							</td>
		 					</tr>	
		 					<tr>
		 							<td>关键词:</td>
		 							<td><input type="text" name="questionKeyword" id="questionKeyword" value="" class="form-control" placeholder="多个用、分隔，至少写一个关键词" /></td>
		 					</tr>	
		 					<tr>
		 							<td>悬赏积分:</td>
		 							<td>
		 									<select name="questionIntegral" id=""  class="form-control">
		 											<option>0</option>
		 											<option>1</option>
		 											<option>2</option>
		 											<option>3</option>
		 											<option>4</option>
		 											<option>5</option>
		 											<option>6</option>
		 											<option>7</option>
		 											<option>8</option>
		 											<option>9</option>
		 											<option>10</option>
		 									</select>
		 							</td>
		 					</tr>	
		 					<tr>
		 							<td>问题描述:</td>
		 							<td>
		 									<textarea rows="4" name="questionDetail" id="questionDetail" cols="70" class="form-control"></textarea>
		 							</td>
		 					</tr>	
		 				</table>
					<div  class="upload-closeDiv">
						<button type="submit" class="btn btn-primary" onclick="javascript:uploadRes(); return false;" style="margin-right: 10px;">确定</button>
						<button type="button" class="btn btn-info" onclick="javascript:hideAlertDiv()" >取消</button>
					</div>
		 		</form>
				</div>
	</div>
	<div id="question-add-bg" class="question-add-bg" style="display:none;" ></div> 	
</body>
<script type="text/javascript">
	function showDiv(){
		document.getElementById("question-add-div").style.display='block';
		document.getElementById("question-add-bg").style.display='block';
	}
	
	function hideAlertDiv(){
		document.getElementById("question-add-div").style.display='none';
		document.getElementById("question-add-bg").style.display='none';
	}
	
	
	function uploadRes(){
			var questionTitle = $('#questionTitle').val();
			var questionDetail = $('#questionDetail').val();
			if(questionTitle == '' || questionDetail == ''){
				alert('标题或者描述不能为空!');
				return;
			}
			var questionKeyword = $('#questionKeyword').val();
			if(!questionKeyword || questionKeyword.split(",").length <1){
				alert('至少写一个关键词!');
				return;
			}
			document.getElementById("question-add-form").onsubmit();
	}
</script>
</html>
